package com.xyebank.ledger.service.lkl.adapter;

import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LRepaymentInf;
import com.xyebank.ledger.service.common.conveter.RePayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateConverter;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.vo.deal.LKLCashInfVo;

@Component(value = "lklRepaymentBeanConverter")
public class LKLRepaymentBeanConverter implements RePayBeanConverter<LKLCashInfVo> {
    

    ModelMapper             modelMapper   = new ModelMapper();

    class LKLRepaymentPropertyMap extends PropertyMap<LKLCashInfVo, LRepaymentInf> {
        protected void configure() {
            map(source.getContractNo(), destination.getOrgOrderNo());
            // modelmapper会自动映射time/amount结尾的key, 这里不手动处理会出问题
            map(null, destination.getCashAmount());
            // mblNo 可以提供, 但是产品表未要求
            //map(source.getMblNo(), destination.getMblNo());
        }
    }



    public LKLRepaymentBeanConverter() {
        modelMapper.addMappings(new LKLRepaymentPropertyMap());
    }



    @Override
    public LRepaymentInf covert(LKLCashInfVo x) {
        LRepaymentInf entity = modelMapper.map(x, LRepaymentInf.class);
        /**
         * channel YDSJD1-手机贷； YDSJD2-享宇钱包；
         */
        entity.setId(IDUtil.generateId(x.getId().toString(), "lkl"));
        entity.setDataSource(x.getChannel().equals("YDSJD2") ? CommonConstant.JRY_STR : CommonConstant.SJD_STR);
        entity.setXyOrgNo(ProductConstant.LKL_LOAN_ORG);
        entity.setXyProductNo(ProductConstant.LKL_LOAN_PROD_ID);
        return entity;
    }
}
